<?php
require("./myadmin/public/mysql.php");
//启动相关

if(isset($_GET['type'])){
	$type = $_GET['type'];
}else{
	$type = "";
}
require("myadmin/public/conn.php");

if($type == "pvf_md5"){
	exit($pvf_md5);
}
if($type=="login_title"){
	exit($login_title);
}
if($type=="keys_word"){
	exit($keys_word."|".$keys_word_1."|".$keys_word_2."|".$keys_word_3);
}
if($type=="auto_update"){
	exit($auto_update);
}
if($type=="update_info"){
	exit($update_info);
}
if($type=="home_link"){
	exit($home_link);
}

if($type=="rech_link"){
	exit($rech_link);
}
if($type=="buy_link"){
	exit($buy_link);
}
if($type=="patch_link"){
	exit($patch_link);
}

if($type=="pvf_control"){
	exit($pvf_control);
}
if($type=="bubble_control"){
	exit($bubble_control);
}
if($type=="checkcode"){
	session_start();
	require_once('code.class.php');
	$code = new code();
	$code->width = 120;
	$code->height = 45;
	$code->Generate();
	$_SESSION['code'] = Verify($code);
	exit($_SESSION['code']);
}
//服务器能否能连接
@$conn = mysql_connect($host,$user,$pass);
if(@!$conn){
	exit("Database connection faile!");
}

mysql_query("set names gbk");

//登录相关

If(Isset($_GET['username']) && Isset($_GET['password']) && $type=="login"){
	$username = $_GET['username'];//获取账号
	$password = $_GET['password'];//获取密码
	$ip = $_SERVER["REMOTE_ADDR"];
	if($ip=='::1'){
	$ip="127.0.0.1";
	}
	If(!Preg_match('/^[0-9A-Za-z]+$/',$username)){//验证账号是否符合标准
		Echo "user erro";
		Exit;
	}
	If(!Preg_match('/^[0-9A-Za-z]+$/',$password)){
		Echo "pass erro";
		Exit;
	}
	$sql = mysql_query("select UID,accountname,password from d_taiwan.accounts where accountname='$username' and password='$password'");//验证账号密码
	If(mysql_num_rows($sql)==0){
		Echo "fail";//提示账号或密码错误
		Exit;//停止代码继续执行
	}Else{
		$str = mysql_fetch_array($sql);
		$uid = $str['UID'];//获取UID
		$m_id = $uid + 10000;//ID偏移
//封杀帐号
		$sql = mysql_query("select BUID from taiwan_siroco.blacklist where BUID='$uid'");
		if(mysql_num_rows($sql) != 0){
			exit("GAME OVER");
		}
//封杀IP
		$sql = mysql_query("select BIP from taiwan_siroco.blacklist where BIP='$ip'");
		if(mysql_num_rows($sql) != 0){
			exit("GAME OVER");
		}	
		$sql = mysql_query("select m_id from taiwan_login.allow_proxy_user where m_id='$uid'");
		if(mysql_num_rows($sql) == 0){
				mysql_query("insert into taiwan_login.allow_proxy_user(m_id)values($uid)");//6848修复
			}		
		require("dnf.php");
		echo $uid,"|",$encrypted,"\n";//返回UID
		$sql = mysql_query("select m_id,charac_no,lev from taiwan_cain.charac_info where m_id=$uid and lev>=70");
		if(mysql_num_rows($sql) != 0){
			while($str = mysql_fetch_array($sql)){
				$cid = $str['charac_no'];
				mysql_query("update taiwan_cain.charac_stat set add_slot_flag=3 where charac_no=$cid");
			}
		}
		mysql_query("update taiwan_cain.charac_stat set village=11 where village=13");//镇魂卡角色修复
		mysql_query("update taiwan_login.member_login set m_id=$uid where m_id=$m_id");//修复数据异常
		mysql_query("update d_taiwan.limit_create_character set count=0 where m_id='$uid'");//取消角色创建限制
		//mysql_query("delete from d_taiwan.member_punish_info where m_id='$uid'");//取消保护 解封帐号
		mysql_query("update taiwan_login.member_play_info set play_count=play_count+1 where m_id='$uid'");
		exit;
	}
}

if(isset($_GET['uid']) && $type=="black_list"){
	$uid = $_GET['uid'];
	$ip = $_SERVER["REMOTE_ADDR"];
	if($ip=='::1'){
	$ip="127.0.0.1";
	}
	$sql = mysql_query("select BID,BUID from taiwan_siroco.blacklist where BUID='$uid' or BIP='$ip'");
	if(mysql_num_rows($sql) != 0){
		exit("GAME OVER");
	}
}

if(Isset($_GET['username']) && Isset($_GET['password']) && isset($_GET['qq_num']) && isset($_GET['check_code']) && $type=="reg"){
	session_start();
	require_once('code.class.php');
	$check_code = $_GET['check_code'];
	$username = $_GET['username'];//获取账号
	$password = $_GET['password'];//获取密码
	$qq_num = $_GET['qq_num'];
	if(isset($_SESSION['code'])){
		if($_SESSION['code'] != strtoupper($check_code)){
			exit("code_error");
		}
	}else{
		exit("code fail");
	}
	if(!preg_match('/^[0-9A-Za-z]+$/',$username)){
		exit("user erro");
	}
	if(!Preg_match('/^[0-9A-Za-z]+$/',$password)){
		exit("pass erro");
	}
	if(!Preg_match('/^[1-9]\\d{4,10}$/',$qq_num)){
		exit("qq erro");
	}
	$ip = $_SERVER["REMOTE_ADDR"];
	if($ip=='::1'){
	$ip="127.0.0.1";
	}
	if($ip_reg_control == "1"){
		$sql = mysql_query("select UID,qq from d_taiwan.accounts where ip='$ip'");
		if(mysql_num_rows($sql) >= $reg_num+1){
			exit("ip_repeat");
		}
	}
	
	$sql = mysql_query("select UID,accountname from d_taiwan.accounts where accountname='$username'");
	if(mysql_num_rows($sql)==0){
		$sql = mysql_query("select UID from d_taiwan.accounts order by UID desc limit 1");//获取最大UID
		if(mysql_num_rows($sql)==0){
			$uid = 18000000;//得到注册ID
		}else{
			$str = mysql_fetch_array($sql);
			$uid = $str['UID'] + 1;//得到注册ID
		}
		$date = date("Y-m-d");
		//执行注册
		
		if(mysql_query("insert into d_taiwan.accounts (UID,accountname,password,qq,ip) VALUES ('$uid','$username','$password','$qq_num','$ip')")){
			mysql_query("insert into d_taiwan.limit_create_character (m_id) VALUES ('$uid')");
			mysql_query("insert into d_taiwan.member_info (m_id,user_id) VALUES ('$uid','$uid')");
			mysql_query("insert into d_taiwan.member_join_info (m_id) VALUES ('$uid')");
			mysql_query("insert into d_taiwan.member_miles (m_id) VALUES ('$uid')");
			mysql_query("insert into d_taiwan.member_white_account (m_id) VALUES ('$uid')");
			mysql_query("insert into taiwan_login.member_login (m_id) VALUES ('$uid')");
			mysql_query("insert into taiwan_billing.cash_cera (account,cera,mod_date,reg_date) VALUES ('$uid','$send_gold',now(),now())");
			mysql_query("insert into taiwan_billing.cash_cera_point (account,cera_point,reg_date,mod_date) VALUES ('$uid','0',now(),now())");
			mysql_query("insert into taiwan_login.member_play_info (occ_date,m_id,server_id) VALUES ('$date','$uid','1')");
			session_unset($_SESSION['code']);
			exit("reg success");
		}else{
			exit("reg fail");
		}
	}else{
		exit("repeat");
	}
}

If(Isset($_GET['username']) && Isset($_GET['ypassword']) && Isset($_GET['xpassword']) && Isset($_GET['check_code']) && $type=="upd_pas"){
	session_start();
	require_once('code.class.php');
	$username = $_GET['username'];
	$ypassword = $_GET['ypassword'];
	$xpassword = $_GET['xpassword'];
	$check_code = $_GET['check_code'];
	if($_SESSION['code'] != strtoupper($check_code)){
		Exit("code_error");
	}
	If(!Preg_match('/^[a-z0-9_＼-]+$/i',$username)){//验证账号是否符合标准
		Echo "user erro";//提示账号非法
		Exit;//停止代码继续执行
	}
	If(!Preg_match('/^[a-z0-9_＼-]+$/i',$ypassword)){//验证账号是否符合标准
		Echo "pass erro";//提示旧密码非法
		Exit;//停止代码继续执行
	}
	If(!Preg_match('/^[a-z0-9_＼-]+$/i',$xpassword)){//验证账号是否符合标准
		Echo "pass erro";//提示新密码非法
		Exit;//停止代码继续执行
	}
	$sql = mysql_query("select UID,accountname,password from d_taiwan.accounts where accountname='$username' and password='$ypassword'");//验证账号密码
	If(mysql_num_rows($sql)==0){
		Echo "old pass fail";//提示账号或密码错误
		Exit;//停止代码继续执行
	}Else{
		$str = mysql_fetch_array($sql);//参数切割
		$uid = $str['UID'];//获取UID
	}
	If(mysql_query("update d_taiwan.accounts set password='$xpassword' where UID='$uid'")){//执行修改
		Echo "uppass success";//提示成功
		Exit;//停止代码继续执行
	}Else{
		Echo "uppass fail";//提示失败
		Exit;//停止代码继续执行
	}
}

//If(Isset($_GET['uid']) && $type=="login_out"){
//	$uid = $_GET['uid'];
//	If(!Preg_match('/^[0-9A-Za-z]+$/',$uid)){//验证账号是否符合标准
//		Echo "fail";//提示账号非法
//		Exit;//停止代码继续执行
//	}
//	mysql_query("INSERT INTO d_taiwan.member_punish_info (m_id, punish_type, occ_time, punish_value, apply_flag, start_time, end_time, admin_id, reason) VALUES ('$uid', '1', '2015-10-31 00:00:00', '101', '2', '2015-10-31 00:00:00', '9999-12-31 23:59:59', 'GM', 'GM')");
//	exit;
//	}

if(isset($_GET['uid']) && isset($_GET['sid']) &&$type == "charac_no"){
	$uid = $_GET['uid'];
	$sid = $_GET['sid'];
	If(!Preg_match('/^[0-9]+$/',$uid)){//验证uid是否符合标准
	exit("0");
	}
	If(!Preg_match('/^[0-9]+$/',$sid)){//验证角色ID是否符合标准
	exit("0");
	}
	$sql = mysql_query("select charac_no from taiwan_cain.charac_info where m_id='$uid' and delete_flag = 0");
	if(mysql_num_rows($sql) == 0){
	exit("0");
	}else{
		$i=0;
		while($str = mysql_fetch_array($sql)){
			$i++;
			if($i==intval($sid)){
			exit($str['charac_no']);
			};     
		}
}
	exit("0");
}

//获取角色
if(isset($_GET['uid']) && $type == "charac"){
	mysql_query("set names latin1");
	$uid = $_GET['uid'];
	If(!Preg_match('/^[0-9]+$/',$uid)){//验证uid是否符合标准
		exit("");
	}
	$sql = mysql_query("select m_id,charac_no,charac_name,lev from taiwan_cain.charac_info where m_id='$uid' and delete_flag = 0");
	if(mysql_num_rows($sql) == 0){
		exit("");
	}else{
		while($str = mysql_fetch_array($sql)){
			echo $str['charac_no']."|".$str['charac_name']."  (Lv:".$str['lev'].")"."\r\n";
		}
	}
}

if($type == "game_text"){
	If($game_text_control=="0"){
		exit;
		}
	$tmp=str_replace("online","tmp_max",$game_text);
	if($tmp!=$game_text){
	$game_online=mysql_num_rows(mysql_query("select login_status from taiwan_login.login_account_3 where login_status=1"));
	$tmp=str_replace("tmp_max",$game_online,$tmp);
	}
	exit($tmp);	
}
//CDK充值
if(isset($_GET['cid']) && isset($_GET['cdk'])&& Isset($_GET['check_code'])&& $type=="cdk"){
	$nid = $_GET['cid'];
	$cdk = $_GET['cdk'];
	$check_code = $_GET['check_code'];
	$first = 0;
	if($check_code!="no_code"){
	session_start();
	require_once('code.class.php');
	if(isset($_SESSION['code'])){
		if($_SESSION['code'] != strtoupper($check_code)){
			exit("code_error");
		}
	}else{
		exit("code fail");
	}
	}	
	$sql = mysql_query("select CState from taiwan_siroco.cdk where CState='1' and CCDK='$cdk'");
	if(mysql_num_rows($sql) != 0){
		exit(iconv("utf-8","gbk","当前CDK序列号已被使用"));
	}
	$sql = mysql_query("select * from taiwan_siroco.cdk where CCDK='$cdk'");
	if(mysql_num_rows($sql) == 0){
		exit(iconv("utf-8","gbk","无效的CDK序列号"));
	}
	mysql_query("set names latin1");
	$str = mysql_fetch_array($sql);
	$code = explode(",",$str['CCode']);
	$title = $str['CName'];
	$number = explode(",",$str['CNumber']);
	$gold = $str['CGold'];
	$d_gold = $str['CDGold'];
	$date = date("Y-m-d H:i:s");
	//执行CDK兑换
	if(mysql_query("update taiwan_siroco.cdk set CState=1,occ_time='$date',charac_id='$nid' where CCDK='$cdk'")){
	$cdk_tmp=1;
	if($cdk_num_control == "1"){
	$cdk_num_startime=date("Y-m-d", $cdk_num_startime); 
	$cdk_num_endtime=date("Y-m-d", $cdk_num_endtime); 
	if(strtotime($cdk_num_endtime)>strtotime($cdk_num_startime)){
	$cdk_numtime=intval($cdk_numtime);
	echo(iconv("utf-8","gbk","活动中").$cdk_numtime.iconv("utf-8","gbk","倍CDK"));	
	}else{
		$cdk_numtime=1;	
	}
	}else{
		$cdk_numtime=1;	
	}
	while($cdk_tmp<=$cdk_numtime) {
	$name = "DNF管理员";
	$content = "CDK兑换物品【".iconv("gbk","utf-8",$title)."】\r\n兑换时间：".$date;
	mysql_query("insert into taiwan_cain_2nd.letter (charac_no,send_charac_no,send_charac_name,letter_text,reg_date,stat)  values ('$nid','0','$name','$content','$date','1')");
	$sql = mysql_query("select letter_id from taiwan_cain_2nd.letter order by letter_id desc limit 1");
	$str = mysql_fetch_array($sql);
	$lid = $str['letter_id'];
	if(count($code) >= 10){
		$goods_i = 10;
	}else{
		$goods_i = count($code);
	}
	mysql_query("insert into taiwan_cain_2nd.postal value ('',now(), '', '$name', '$nid', '".$code[0]."', '".$number[0]."', '0', '0', '0', '0', '$gold', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '$lid', '0', '0', '0', '', '0', 0x0000000000000000000000000000, '', '0', 0x00000000000000000000)");
	for($i=1;$i<$goods_i;$i++){
		mysql_query("insert into taiwan_cain_2nd.postal value ('',now(), '', '$name', '$nid', '".$code[$i]."', '".$number[$i]."', '0', '0', '0', '0', '0', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '$lid', '0', '0', '0', '', '0', 0x0000000000000000000000000000, '', '0', 0x00000000000000000000)");
	}
	$sql = mysql_query("select account,cera_point from taiwan_billing.cash_cera_point where account=(select m_id from taiwan_cain.charac_info where charac_no=$nid)");
	if(mysql_num_rows($sql) != 0){
		mysql_query("update taiwan_billing.cash_cera_point set cera_point=cera_point+$d_gold where account=(select m_id from taiwan_cain.charac_info where charac_no=$nid)");
	}
	$cdk_tmp++;
	}
	//首次充值CDK奖励判断
	if($frist_control == "1"){
	$sql = mysql_query("select charac_id from taiwan_siroco.charac_first where charac_id=$nid and occ_first");
	if(mysql_num_rows($sql)==0){
		$first = 1;
	//首充SQL奖励语句 并且增加表项
		mysql_query("insert into taiwan_siroco.charac_first (charac_id,occ_first) values ('$nid','1')");
		$content = "首次充值CDK奖励\r\n奖励游戏金币：$frist_reward_money\r\n发送时间：$date";
		mysql_query("insert into taiwan_cain_2nd.letter (charac_no,send_charac_no,send_charac_name,letter_text,reg_date,stat)  values ('$nid','0','$name','$content','$date','1')");
		$sql = mysql_query("select letter_id from taiwan_cain_2nd.letter order by letter_id desc limit 1");
		$str = mysql_fetch_array($sql);
		$lid = $str['letter_id'];
		if(count($frist_reward_goods) > 10){
			$goods_i = 10;
		}else{
			$goods_i = count($frist_reward_goods);
		}
		mysql_query("insert into taiwan_cain_2nd.postal value ('',now(), '', '$name', '$nid', '".$frist_reward_goods[0][1]."', '".$frist_reward_goods[0][2]."', '0', '0', '0', '0', '$frist_reward_money', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '$lid', '0', '0', '0', '', '0', 0x0000000000000000000000000000, '', '0', 0x00000000000000000000)");
		for($i=1;$i<$goods_i;$i++){
		if($frist_reward_goods[$i][1] == ""){
			continue;
		}
		mysql_query("insert into taiwan_cain_2nd.postal value ('',now(), '', '$name', '$nid', '".$frist_reward_goods[$i][1]."', '".$frist_reward_goods[$i][2]."', '0', '0', '0', '0', '0', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '$lid', '0', '0', '0', '', '0', 0x0000000000000000000000000000, '', '0', 0x00000000000000000000)");
		}
		}
	}
	if($first==1){
		exit(iconv("utf-8","gbk","CDK充值成功 本次为首充\r\n获得【").$title.iconv("utf-8","gbk","】\r\n请小退游戏查收邮件\r\n首充温馨提示:").$frist_reward_title);
		}else{
		exit(iconv("utf-8","gbk","兑换成功\r\n获得【").$title.iconv("utf-8","gbk","】\r\n请小退游戏查收邮件"));	
	}
	}else{
		exit(iconv("utf-8","gbk","兑换失败\r\n请联系管理员检查数据库表"));
	}
}

//泡点工具
if($type == "bubble"){
	echo $now_time."|";
	echo $reward_gold."|";
	echo $gold_type;
	exit;
}

if($type == "now_time"){
	echo $now_time;
	exit;
}

if($type == "reward_time"){
	echo $reward_time;
	exit;
}

if(isset($_GET['uid']) && isset($_GET['time']) && $type == "reward_bubble"){
	session_start();
	$now = time(); //当前时间
	$uid = $_GET['uid'];
	$time = $_GET['time'];
	if (isset($_SESSION['last_times']) && $now - $_SESSION['last_times'] < $reward_time) {     //时间验证
	exit("time fail");
	} else 
	If(!Preg_match('/^[0-9A-Za-z]+$/',$uid)){//验证账号是否符合标准
		exit(iconv("utf-8","gbk","未知错误"));
	}

	if($time > time()){
		exit("fail");
	}else{
		$_SESSION['last_times'] = $now; //记录提交时间
		if($gold_type == "1"){
			mysql_query("update taiwan_billing.cash_cera set cera=cera+$reward_gold where account=$uid");
			exit("success");
		}
		if($gold_type == "2"){
			mysql_query("update taiwan_billing.cash_cera_point set cera_point=cera_point+$reward_gold where account=$uid");
			exit("success");
		}
		if($gold_type == "3"){
			mysql_query("update taiwan_siroco.gold set GGold=GGold+$reward_gold where GUID=$uid");
			exit("success");
		}
	}
}
?>